package com.forum.controller;

import java.util.LinkedList;
import java.util.List;

import com.forum.domain.Groups;
import com.forum.domain.GroupsDAO;
import com.forum.domain.Remind;
import com.forum.domain.RemindDAO;
import com.forum.domain.ReplyDAO;
import com.forum.domain.TopicDAO;
import com.forum.domain.Ucg;
import com.forum.domain.UcgDAO;
import com.forum.domain.Uct;
import com.forum.domain.UctDAO;
import com.forum.domain.UcuDAO;
import com.forum.domain.User;
import com.forum.domain.UserDAO;
import com.forum.jspgenerator.GenerateG;
import com.forum.jspgenerator.GenerateP;
import com.forum.jspgenerator.GenerateR_M;

public class MainController {
	
	private GenerateG g_group;
	private GenerateR_M g_rm;
	private GenerateP g_people;
	private UserDAO userdao = new UserDAO();
	private GroupsDAO groupdao = new GroupsDAO();
	private RemindDAO reminddao = new RemindDAO();
	private ReplyDAO replydao = new ReplyDAO();
	private TopicDAO topicdao = new TopicDAO();
	private UcgDAO ucgdao = new UcgDAO();
	private UcuDAO ucudao = new UcuDAO();
	private UctDAO uctdao = new UctDAO();
	//whether it is the first time it created
	public boolean _firstTime = true;
	
	
	public int id;
	public User user;
	
	public MainController(int id)
	{
		this.id = id;
		user = userdao.findById(id);
		g_rm = new GenerateR_M(user);
		g_rm.setReminddao(reminddao);
		g_group = new GenerateG(user);
		g_group.setUcgdao(ucgdao);
		g_people = new GenerateP(user);
		g_people.setUcudao(ucudao);
	}
	
	public List<Remind> getReminds()
	{
		//System.out.println("controller get reminds");
		return g_rm.getReminds();
	}
	
	public List<Groups> getGroups()
	{
		return g_group.getGroups();
	}
	
	public List<Groups> getMoreGroups()
	{
		return g_group.moreGroups();
	}
	
	public List<User> getUsers(){
		return g_people.getUser();
	}
	
	public List<User> getMoreUsers()
	{
		return g_people.moreUsers();
	}
	
	public List getUserFollowInfo(User u)
	{
		List<Ucg> ucglist = ucgdao.findByProperty("user", u);
		List<Uct> uctlist = uctdao.findByProperty("user",u);
		List list = new LinkedList();
		for(int i = 0 ; i<ucglist.size();i++)
		{
			list.add(ucglist.get(i).getGroups());
		}
		for(int i = 0 ; i<uctlist.size();i++)
		{
			list.add(uctlist.get(i).getTopic());
		}
		return list;
	}

}
